<template>
  <div class="list-table">
    <div class="area-header">
      <span class="area-header-title">{{ $t('上会情况') }}</span>
    </div>
    <el-form ref="queryForm" :model="queryParams" :inline="true">
      <el-form-item :label="$t('项目名称')" prop="dealId">
        <MainBodySelect
          v-model="queryParams.dealId"
          parameters="deal"
        />
      </el-form-item>
      <el-form-item :label="$t('会议类型')" prop="mtType">
        <el-select v-model="queryParams.mtType" clearable :placeholder="$t('请选择')">
          <el-option
            v-for="(type, index) in mtTypeOptions"
            :key="index"
            :value="type.id"
            :label="$t(type.mtTypeLabel)"
          />
        </el-select>
      </el-form-item>
      <el-form-item :label="$t('会议结论')" prop="conclusion">
        <dictSelect
          v-model="queryParams.conclusion"
          :clearable="true"
          dictionary="meeting_conclusion"
        />
      </el-form-item>
      <el-form-item :label="$t('会议时间')" prop="meetingTime" label-width="200">
        <DatePicker
          v-model="dateRange"
          type="daterange"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="queryHandle">{{ $t("搜索") }}</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ $t("重置") }}</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <!--      <el-col :span="1.5">-->
      <!--        <el-button-->
      <!--          v-hasPermi="['oa:business:edit']"-->
      <!--          type="primary"-->
      <!--          icon="el-icon-plus"-->
      <!--          size="mini"-->
      <!--          @click="addHandle"-->
      <!--        >{{ $t("新增") }}</el-button>-->
      <!--      </el-col>-->
    </el-row>

    <el-table v-loading="loading" :data="mtSituationList" border>
      <el-table-column :label="$t('序号')" type="index" align="center" show-overflow-tooltip width="50">
        <template slot-scope="scope">
          {{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('项目名称')" align="center" prop="dealName" width="150">
        <template slot-scope="scope">
          <router-link
            target="_blank"
            :to="{path:'/deal/home/dealBaseHome',query:{id:scope.row.dealId,dealType: scope.row.dealType, companyId: scope.row.companyId, menuKey: 'mt_situation', showType: 'deal'}}"
            class="link_a"
            @click.native="recorePath({ fromPath: $route.fullPath, path:'/deal/home/dealBaseHome',query:{id:scope.row.dealId,dealType: scope.row.dealType, companyId: scope.row.companyId, menuKey: 'mt_situation', showType: 'deal'}})"
          >
            {{ scope.row.dealName }}
          </router-link>

        </template>
      </el-table-column>
      <el-table-column :label="$t('会议类型')" align="center" prop="mtTypeLabel" width="130">
        <template slot-scope="scope">
          {{ $t(scope.row.mtTypeLabel) }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('会议结论')" align="center" prop="conclusionLabel" width="150" />
      <el-table-column :label="$t('会议主题')" align="center" prop="meetingTitle" show-overflow-tooltip>
        <template slot-scope="scope">
          <el-link type="primary" @click="updateHandle(scope.row)">{{ scope.row.meetingTitle }}</el-link>
        </template>
      </el-table-column>
      <el-table-column :label="$t('会议地点')" align="center" prop="placeLabel" show-overflow-tooltip />
      <el-table-column :label="$t('会议日期')" align="center" prop="meetingTime" width="180" />
      <el-table-column :label="$t('操作')" fixed="right" align="center" class-name="small-padding fixed-width" width="280">
        <template slot-scope="scope">
          <el-button
            size="small"
            type="text"
            icon="el-icon-edit"
            @click="openMinutes(scope.row)"
          >{{ $t('会议纪要') }}</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改已发起会议对话框 -->
    <el-dialog :title="$t('会议信息')" :visible.sync="formOpen" :destroy-on-close="true" :close-on-click-modal="false" :lock-scroll="false" custom-class="dialogForm" append-to-body>
      <mtBusinessForm ref="mtBusinessForm" :business-detail-id-list="businessDetailIdList" @resetDetailList="resetDetailList" />
    </el-dialog>

    <el-dialog :title="$t('会议纪要')" :visible.sync="minutesOpen" :destroy-on-close="true" :close-on-click-modal="false" width="60%" :lock-scroll="false" custom-class="dialogForm" append-to-body>
      <mtMinutesForm ref="mtMinutesForm" :business-detail-id-list="businessDetailIdList" @resetDetailList="resetDetailList" />
    </el-dialog>

  </div>
</template>

<script>
import { delMtBusiness, listMtSituation } from '@/api/oa/business/mtBusiness'
import mtBusinessForm from './mtBusinessForm.vue'
import mtMinutesForm from './mtMinutesForm.vue'
import { findAll } from '@/api/oa/type/mtType'
import MainBodySelect from '@/components/MainBodySelect/index'

export default {
  components: {
    mtBusinessForm,
    mtMinutesForm,
    MainBodySelect
  },
  props: {
    businessDetailIdList: {
      type: Array,
      default: () => []
    }
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 上会情况表格数据
      mtSituationList: [],
      // 是否显示弹出层
      formOpen: false,
      // 会议纪要
      minutesOpen: false,
      // 会议类型
      mtTypeOptions: [],
      // 会议开始时间
      dateRange: undefined,
      // 查询参数
      queryParams: {
        mtType: undefined,
        conclusion: undefined,
        meetingStartTime: undefined,
        meetingEndTime: undefined,
        startDate: undefined,
        endDate: undefined,
        pageNum: 1,
        pageSize: 10
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    }
  },
  created() {
    this.getList()
    findAll().then(response => {
      this.mtTypeOptions = response.data
    })
  },
  methods: {
    handleClick() {

    },
    /** 查询已发起会议列表 */
    getList() {
      this.loading = true
      listMtSituation(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
        this.mtSituationList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        meetingTitle: undefined,
        meetingType: undefined,
        startTime: undefined,
        meetingTime: undefined,
        participants: undefined,
        internalParticipants: undefined,
        meetingAddress: undefined,
        secretary: undefined,
        externalParticipants: undefined,
        meetingMainTitle: undefined,
        remark: undefined,
        createBy: undefined,
        createTime: undefined,
        updateBy: undefined,
        updateTime: undefined,
        delFlag: undefined
      }
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    queryHandle() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.dateRange = undefined
      this.queryHandle()
    },
    /** 修改按钮操作 */
    updateHandle(row) {
      this.formOpen = true
      this.$nextTick(() => {
        const data = {}
        data.id = row.businessId
        // 调用form页面的 init 方法初始化数据
        this.$refs.mtBusinessForm.init(data)
      })
    },
    /** 删除按钮操作 */
    deleteHandle(row) {
      this.$confirm(this.$t('是否确认删除?'), this.$t('警告'), {
        confirmButtonText: this.$t('确定'),
        cancelButtonText: this.$t('取消'),
        type: 'warning'
      }).then(function() {
        return delMtBusiness(row.id)
      }).then(() => {
        this.getList()
        this.msgSuccess(this.$t('删除成功'))
      }).catch(function() {
      })
    },
    resetDetailList() {
      this.$emit('resetDetailList')
    },
    // 打开会议纪要
    openMinutes(row) {
      this.minutesOpen = true
      this.$nextTick(() => {
        var minutesData = {}
        minutesData.meetingId = row.businessId
        this.$refs.mtMinutesForm.init(minutesData)
      })
    }

  }
}
</script>
